package proxy.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author : DuJiabao
 * @Date : 2021/3/16 11:01
 * @Project : design-pattern
 * @File : null.java
 * @Desc :
 */
public class ProxyFactory {
  private Object target;

  public ProxyFactory(Object target) {
    this.target = target;
  }

  public Object getProxyInstance() {
    return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), new InvocationHandler(){
      @Override
      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("proxy 之前");
        Object res = method.invoke(target, args);
        System.out.println("proxy 之后");
        return res;
      }
    });
  }
}
